package com.zhongke.cotrun.mapper;

import com.zhongke.cotrun.model.pojo.ProjectInfo;
import com.zhongke.cotrun.model.pojo.ProjectInfoVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 作者 yhl
 * 日期 2020-01-05 14:02:19
 * 描述
 */

@Mapper()
public interface ProjectInfoMapper {
    /**
     * 根据主键删除数据
     *
     * @param projectId 主键id
     */
    @Update("update project_info set del_flag = 1 where project_id = #{projectId}")
    int deleteByPrimaryKey(@Param("projectId") Integer projectId);

    /**
     * 使用：插入审核后的数据
     *
     * @param record
     */
    int insertSelective(ProjectInfo record);

    /**
     * 获取最新12条项目信息
     *
     * @return
     */
    List<ProjectInfoVo> listLast12Info();

    /**
     * 根据主键id查询
     *
     * @param projectId
     */
    ProjectInfoVo selectByPrimaryKey(Integer projectId);

    /**
     * 根据主键id查询审核数据
     *
     * @param projectId
     */
    ProjectInfo selectAuditDetailByPrimaryKey(Integer projectId);

    /**
     * 修改数据(推荐使用)
     *
     * @param record
     */
    int updateByPrimaryKeySelective(ProjectInfo record);

    List<ProjectInfoVo> queryProjectList(ProjectInfoVo query);

    /**
     * 根据id下线活动
     *
     * @param projectId
     * @return
     */
    @Update("update project_info set approval_state = 4 where approval_state=1 and project_id = #{projectId}")
    Boolean cancelByPrimaryKey(@Param("projectId") Integer projectId);
    //修改审核
    @Update("update project_info set approval_state=#{approvalState},approval_opinion = #{opinion},approval_user = #{userName},approval_time = now() where project_id = #{projectId}")
    boolean approvalByPrimaryKey(@Param("projectId") Integer projectId, @Param("approvalState") Integer approvalState, @Param("opinion") String opinion, @Param("userName") String userName);
    //批量删除
    @Update("update project_info set del_flag = 1 where project_id in (${ids});")
    boolean deleteBatch(@Param("ids") String ids);
    //批量推荐
    @Update("update project_info set is_recommend = 1 ,recommend_time = now() where approval_state=1 and project_id in (${ids})")
    boolean recommendProject(@Param("ids") String ids);
    //设置推荐
    @Update("update project_info set is_recommend = #{state} ,recommend_time = now() where approval_state=1 and project_id = #{id} ")
    boolean setRecommend(@Param("id") Integer id, @Param("state") Integer state);

    @Select("select count(0) from project_info_view where approval_state = 0 and del_flag = 0")
    int queryUnApprovalCounts();
}